const mongoose = require("./db");

const PermissionsSchema = new mongoose.Schema({
  RoleName: String, // 角色名
  MenuList: Array, // 菜单权限列表
  ButtonList: Array, // 按钮权限列表
  AddTime: Date, // 添加时间
  Description: String, // 描述
  UserIds: [
    {
      type: mongoose.Types.ObjectId,
      ref: "User",
    },
  ],
});

const UserSchema = new mongoose.Schema(
  {
    username: String, // 用户名
    password: String, //密码
    email: String, //邮箱
    phone: String, //手机号码
    smscode: String, //手机验证码
    resettoken: String, //重置密码token
    expirationtime: Number, //重置密码token过期时间
    emailcode: Number, //邮箱验证码
    addTime: Date, // 注册时间
    lastLogin: Date, // 最后登录时间
    status: {
      type: Boolean,
      default: true,
    }, // 是否启用
    permissionsId: [
      {
        // 角色ID
        type: mongoose.Types.ObjectId,
        ref: "Permissions",
      },
    ],
  },
  {
    versionKey: false, // 去掉版本号
  }
);

// 顾客信息
const CustomSchema = new mongoose.Schema({
  id: Number,
  name: String,
  age: Number,
  sex: Number,
  birth: String,
  address: String
});

const UserModel = mongoose.model("User", UserSchema, "User");
const CustomModel = mongoose.model("Custom", CustomSchema, "Custom");
const PermissionsModel = mongoose.model(
  "Permissions",
  PermissionsSchema,
  "Permissions"
);

module.exports = {
  UserModel,
  PermissionsModel,
  CustomModel
};
